package JDKdynamicProxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @Author:zimmor
 * @Date: 2021/3/25 10:35
 * @Description 动态代理封装类
 * @version: 1.0.0
 */

public class DynamicProxy {

    public static Object CreateProxy(final Object target) {
        return Proxy.newProxyInstance(target.getClass().getClassLoader(), target.getClass().getInterfaces(), new InvocationHandler() {
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                System.out.println("代理产生作用");
                return method.invoke(target, args);
            }
        });
    }
}
